home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
errhand.fr_
/
errhand.fr
Wrap
Text File
|
1995-07-19
|
4KB
|
153 lines
VERSION 4.00
Begin VB.Form frmODBC
BackColor = &H00C0C0C0&
Caption = "ODBC Errors"
ClientHeight = 3210
ClientLeft = 2325
ClientTop = 2160
ClientWidth = 2880
Height = 3705
Left = 2220
LinkTopic = "Form1"
ScaleHeight = 3210
ScaleWidth = 2880
Top = 1770
Width = 3090
Begin VB.CommandButton cmdQuit
Caption = "&Quit"
Height = 495
Left = 480
TabIndex = 3
Top = 2400
Width = 1935
End
Begin VB.CommandButton cmdAllochDbc
Caption = "&Allocate hDbc"
Height = 495
Left = 480
TabIndex = 1
Top = 960
Width = 1935
End
Begin VB.CommandButton cmdGetFunctions
Caption = "&Get Functions"
Height = 495
Left = 480
TabIndex = 2
Top = 1560
Width = 1935
End
Begin VB.CommandButton cmdDriverConnect
Caption = "&Driver Connect"
Height = 495
Left = 480
TabIndex = 0
Top = 360
Width = 1935
End
End
Attribute VB_Name = "frmODBC"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdAllochDbc_Click()
Dim result As Integer
'Problem: ghEnv is passed as a null handle
result = SQLAllocConnect(0, ghDbc)
If result <> SQL_SUCCESS Then
result = ODBCError("Dbc", 0, ghDbc, 0, result, "Error allocating connection handle.")
frmODBC.Show
Exit Sub
End If
End Sub
Private Sub cmdDriverConnect_Click()
Dim result As Integer
Dim connStrIn As String
Dim connStrOut As String * SQL_MAX_OPTION_STRING_LENGTH
#If Win32 Then
Dim strOutCount As Long
#Else
Dim strOutCount As Integer
#End If
connStrIn = ""
'Problems: Connect string is empty and function is told
'not to prompt for missing information
result = SQLDriverConnect(ghDbc, Me.hWnd, connStrIn, Len(connStrIn), connStrOut, Len(connStrOut), strOutCount, SQL_DRIVER_NOPROMPT)
If result <> SQL_SUCCESS Then
result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Problem with call to SQLDriverConnect.")
Exit Sub
End If
'Free the connection, but not the handle
result = SQLDisconnect(ghDbc)
If result <> SQL_SUCCESS Then
result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Problem with call to SQLDriverConnect.")
End If
End Sub
Private Sub cmdGetFunctions_Click()
Dim result As Integer
Dim FuncList(100) As Integer
'Problem: second argument requests information about a
'particular function or all functions. The number must
'be positive.
result = SQLGetFunctions(ghDbc, -5, FuncList(0))
If result <> SQL_SUCCESS Then
result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error getting list of ODBC functions")
Screen.MousePointer = DEFAULT
Exit Sub
End If
End Sub
Private Sub cmdQuit_Click()
End
End Sub
Private Sub Form_Load()
'Log on to an ODBC data source
'First, allocate ODBC memory and get handles
Dim result As Integer
Dim fHeight As Integer, fWidth As Integer
Dim fTop As Integer, fLeft As Integer
'Resize and center the form
fLeft = (Screen.Width - frmODBC.Width) / 2
fTop = (Screen.Height - frmODBC.Height) / 2
frmODBC.Move fLeft, fTop
'Allocate the ODBC environment handle
result = ODBCAllocateEnv(ghEnv)
If result <> SQL_SUCCESS Then
End
End If
result = SQLAllocConnect(ghEnv, ghDbc)
If result <> SQL_SUCCESS Then
result = ODBCError("Dbc", ghEnv, ghDbc, 0, result, "Error allocating connection handle.")
End
End If
frmODBC.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim result As Integer
result = ODBCDisconnectDS(ghEnv, ghDbc, ghStmt)
result = ODBCFreeEnv(ghEnv)
End Sub